package com.whj.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.whj.entity.Goods;
import com.whj.service.GoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@ResponseBody
@Slf4j
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodService goodService;
    @RequestMapping("/showGoodsPage")
    public ModelAndView showGoodsPage(ModelAndView modelAndView, Integer pageNum) {
        IPage<Goods> goodsIPage = goodService.showGoodsPage(pageNum);

        modelAndView.addObject("goodsPages", goodsIPage);

        modelAndView.setViewName("shop");
        return modelAndView;
    }
    @RequestMapping("/showGoodsDetail")
    public ModelAndView showGoodsDetail(ModelAndView modelAndView, Integer id) {
        Goods goods = goodService.showGoodsDetail(id);
        modelAndView.addObject("goods", goods);
        modelAndView.setViewName("shop-detail");
        return modelAndView;
    }

}
